/**
 * 本地存储的 存,取,删
 */

/**
 * 存
 */
export const setItem = (key, value) => {
  // 如果value值是数组或者对象
  if (typeof value === 'object' && value !== null) {
    value = JSON.stringify(value)
  }
  window.localStorage.setItem(key, value)
}

/**
 * 取
 */
export const getItem = key => {
  const value = window.localStorage.getItem(key)
  // try catch 尝试解json
  try {
    return JSON.parse(value)
  } catch (error) {
    return value
  }
}

/**
 * 删
 */

export const removeItem = key => {
  window.localStorage.removeItem(key)
}
